#include<stdio.h>
#include<stdlib.h>

int *fun(){
	//局部变量a,存放在栈区，空间随着函数结束自动释放
	//int a = 5;
	//动态申请空间，存放在堆区，手动释放之后才结束
	int *a = NULL;

	a = malloc(12);
	if(NULL == a){
		printf("malloc failed\n");
		return NULL;
	}

	*a = 10;
	return a;
}

int main(int argc, const char *argv[]){
	int *p = NULL;
	p = fun();
	printf("%d\n", *p);//10

	//一次分配对应一次释放，释放多了程序会报错
	free(p);
	return 0;
}
